package com.student.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.student.pojo.Classes;
import com.student.pojo.Student;
import com.student.service.ClassesService;
import com.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * @author 是一个鸽子啊
 * @date 2020/4/14
 * @qq 364826415
 */
@RestController
public class StudentAjaxController {
    @Autowired
    @Qualifier("StudentServiceImpl")
    private StudentService studentService;
    @Autowired
    @Qualifier("classesServiceImpl")
    private ClassesService classesService;
    @RequestMapping("/queryStudentByID")
    private String queryStudentByID(String studentID, HttpServletRequest request) throws JsonProcessingException {
        Student student = studentService.queryStudentByID(Integer.parseInt(studentID));
        ObjectMapper objectMapper = new ObjectMapper();
        String val = objectMapper.writeValueAsString(student);
        return val;
    }
    @RequestMapping("/queryStudentC")
    private String queryStudentC() throws JsonProcessingException {
        List<Classes> classesList = classesService.queryClasses();
        ObjectMapper objectMapper = new ObjectMapper();
        String val = objectMapper.writeValueAsString(classesList);
        return val;
    }
}
